import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import pinia from './store'
import PanelHead from './components/PanelHead.vue'



// element-plus图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}




app.use(router)
app.use(pinia)
app.component(PanelHead)
app.mount('#app')


import { UseMenuStore } from "../src/store/index";
const UseMenuStores = UseMenuStore();

import { computed, toRaw } from 'vue'
import { menuPermissions, } from "./api/index";
if (UseMenuStores.routerList.length > 0) {
    // 新路由数据
    const routerList = computed(() => UseMenuStores.routerList);
    // 获取菜单权限
    menuPermissions().then(({ data }) => {
        UseMenuStores.dynamicMenu(data.data);
        // console.log(data);
        // routerList.value = UseMenuStores.routerList;
        toRaw(routerList.value).forEach((item) => {
            router.addRoute("main", item);
        });
        // console.log(routerList);
        UseMenuStores.routerList = routerList.value;
        // 跳转主页面
        router.push(`${UseMenuStores.RouterPath}`);
    });
}